package com.cloudkinto.controller.order.shelf;


import com.cloudkinto.base.BaseController;
import com.cloudkinto.bo.order.shelf.*;
import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.service.order.shelf.OrderInputShelfService;
import com.cloudkinto.vo.order.shelf.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 入库产品上架表（中间表） 前端控制器
 * </p>
 *
 * @author long
 * @since 2024-11-07
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "上架模块")
@RequestMapping("/api/admin/wms/order/input/shelf")
public class OrderInputShelfWmsController extends BaseController {
    private final OrderInputShelfService orderInputShelfService;

    @UserSessionRequired
    @GetMapping("/{id}")
    @ApiOperation(value = "上架根据id查看详情", notes = "上架根据id查看详情")
    public SingleResult<OrderInputShelfDetailVo> detail(@PathVariable("id") Long id) {
        return SingleResult.success("查询成功", orderInputShelfService.detail(id, getTenantId()));
    }

    @UserSessionRequired
    @GetMapping("/pageInit")
    @ApiOperation(value = "上架查询初始化", notes = "上架查询初始化")
    public SingleResult<Map<String, Object>> pageInit() {
        return orderInputShelfService.pageInit(getCurrentUserId(), getTenantId(), "wms");
    }

    @UserSessionRequired
    @PostMapping("/listPage")
    @ApiOperation(value = "上架分页", notes = "上架分页")
    public PageResult<OrderInputShelfListVo> listPage(@RequestBody OrderInputShelfQueryBo bo) {
        bo.setWhId(getWarehouseId());
        return orderInputShelfService.getListPage(bo);
    }

    @UserSessionRequired
    @PostMapping("/listPageStatusStatistics")
    @ApiOperation(value = "分页查询状态数量统计", notes = "分页查询状态数量统计")
    public SingleResult<List<Map<String, Object>>> listPageStatusStatistics(@RequestBody OrderInputShelfQueryBo bo) {
        bo.setWhId(getWarehouseId());
        return orderInputShelfService.getListPageStatus(bo);
    }

    @UserSessionRequired
    @GetMapping("/shelfDetailInit")
    @ApiOperation(value = "上架详情初始化", notes = "上架详情初始化")
    public SingleResult<Map<String, Object>> shelfDetailInit() {
        return orderInputShelfService.shelfDetailInit(getTenantId());
    }

    @UserSessionRequired
    @PostMapping("/shelfDetail")
    @ApiOperation(value = "上架详情", notes = "上架详情")
    public SingleResult<ShelfDetailVo> shelfDetail(@RequestBody ShelfDetailQueryBo bo) {
        return SingleResult.success(orderInputShelfService.shelfDetail(bo));
    }

    @UserSessionRequired
    @PostMapping("/shelfBySkuListPage")
    @ApiOperation(value = "根据id查看上架页产品详情(常规入库按产品)", notes = "根据id查看上架页产品详情(常规入库按产品)")
    public PageResult<ShelfBySkuVo> shelfBySkuListPage(@RequestBody @Validated ShelfBySkuQueryBo bo) {
        return orderInputShelfService.shelfBySkuListPage(bo);
    }

    @UserSessionRequired
    @PostMapping("/shelfByBoxMarkNoListPage")
    @ApiOperation(value = "根据id查看上架页产品详情(常规入库按箱)", notes = "根据id查看上架页产品详情(常规入库按箱)")
    public PageResult<ShelfByBoxMarkNoVo> shelfByBoxMarkNoListPage(@RequestBody @Validated ShelfByBoxMarkNoQueryBo bo) {
        return orderInputShelfService.shelfByBoxMarkNoListPage(bo);
    }

    @UserSessionRequired
    @PostMapping("/shelfByBoxTypeNoListPage")
    @ApiOperation(value = "根据id查看上架页产品详情(备货中转)", notes = "根据id查看上架页产品详情(备货中转)")
    public PageResult<ShelfByBoxTypeNoVo> shelfByBoxTypeNoListPage(@RequestBody @Validated ShelfByBoxTypeNumberQueryBo bo) {
        return orderInputShelfService.shelfByBoxTypeNoListPage(bo);
    }

    @UserSessionRequired
    @PostMapping("/shelfByBoxMarkNo")
    @ApiOperation(value = "按箱上架(常规入库按箱)", notes = "按箱上架(常规入库按箱)")
    public SingleResult<Boolean> shelfByBoxMarkNo(@RequestBody @Validated ShelfByBoxMarkNumberAddBo bo) {
        return SingleResult.success("上架成功", orderInputShelfService.shelfByBoxMarkNumber(bo, getCurrentUserId(), getUserName()));
    }

    @UserSessionRequired
    @PostMapping("/shelfBySku")
    @ApiOperation(value = "按产品上架(常规入库按产品)", notes = "按产品上架(常规入库按产品)")
    public SingleResult<Boolean> shelfBySku(@RequestBody @Validated ShelfBySkuAddBo bo) {
        return SingleResult.success("上架成功", orderInputShelfService.shelfBySku(bo, getCurrentUserId(), getUserName()));
    }

    @UserSessionRequired
    @PostMapping("/shelfByBoxTypeNo")
    @ApiOperation(value = "备货中转入库上架", notes = "备货中转入库上架")
    public SingleResult<Boolean> shelfByBoxTypeNo(@RequestBody @Validated ShelfByBoxTypeNumberAddBo bo) {
        return SingleResult.success("上架成功", orderInputShelfService.shelfByBoxTypeNo(bo, getCurrentUserId(), getUserName()));
    }

    @UserSessionRequired
    @GetMapping("/partShelfOption/{pasId}")
    @ApiOperation(value = "部分上架方式选择按钮", notes = "部分上架方式选择")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "1按产品2按箱", response = Integer.class)
    })
    public SingleResult<Integer> partShelfOption(@PathVariable("pasId") Long pasId) {
        return SingleResult.success(orderInputShelfService.partShelfOption(pasId));
    }

    @UserSessionRequired
    @GetMapping("/shelfPrint/{pasId}")
    @ApiOperation(value = "上架单打印", notes = "上架单打印")
    public void shelfPrint(@PathVariable("pasId") Long pasId, HttpServletResponse response) throws IOException {
        orderInputShelfService.shelfPrint(pasId, response);
    }

}

